﻿<%@ Page Title="" Language="C#" MasterPageFile="~/master/m.master" %>
<script runat="server"></script>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
<link href="../assets/css/plugins/footable/footable.core.css" rel="stylesheet" />
<link href="../assets/css/shelf/base.css" rel="stylesheet" />
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="main" Runat="Server">
    <div class="system-box">
	<div class="right-side">
	    <div class="btns-container"></div>
        <div class="condition">
        	<label>搜索关键字</label>
        	<input id="keys" class="form-control input-w160" placeholder="店铺编号或名称" />
        	<label>货号</label>
        	<select id="search-season" class="form-control input-w160">
				<option value="">所有</option>
			</select>
			<label>尺码</label>
			<select id="search-size-name" class="form-control input-w160">
				<option value="">所有</option>
                <option value="S">S</option>
                <option value="M">M</option>
                <option value="L">L</option>
			</select>
		</div>
        <div class="right-content-box">
			<div class="ibox-content">
				<table class="footable table table-stripped">
					<thead></thead>
					<tbody id="pageList"></tbody>
				</table>
			</div>
		</div>
		<div class="pageControl"></div>
	</div>
</div>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="footer" Runat="Server">
    <script src="../assets/js/page/pageControl.js"></script>
    <script src="../assets/js/page/rScroll.js"></script>
    <script src="../assets/js/page/tableControl.js"></script>
    <script src="../assets/js/framework.js"></script>
    <script type="application/javascript">
    $(document).ready(function(){
        //模块ID
        var ModuleID = Y.getUrlParam("ModuleID");
        //用于记录页数
        var page = 1;
        //用于记录每页多少条记录
        var size = 10;
        //用于记录各项信息
        var pageList = [];
        commonUtil.loadBtnList(ModuleID, function () {
            rScroll();
        });
        //加载信息列表
        var loadList = function () {
            if ($('.footable thead').children().size() == 0)
                tableControl.initThead2('.footable', ['店铺名称','仓库编号', '商品代码', '尺码', '需求数量', '库存数量', '实际补货数量', '补货时间', '补货轮次']);

            $('.detail-box').fadeOut();
            var keys = $('#keys').val().trim().replace(/'/g, '');            
            pageControl.init('DwSupplyRound', 'GetDwSupplyRound', {
                Keys: keys,
                Page: page,
                //Size: size,
            }, function (result) {
                page = result.page;
                var tBody = [];
                if (!Y.checkNull(result.data)) {
                    result.data.Items.map(function (item, i) {
                            var tempTr = {
                                trClass: (i % 2 == 0 ? 'gradeX footable-even' : 'gradeX footable-odd'),
                                children: [
                                    { tdText: (item.ShopName || ' '), c: 0, r: 0, tdHtml: '', tdId: '', tdClass: '' },
                                    { tdText: (item.StockID || ' '), c: 0, r: 0, tdHtml: '', tdId: '', tdClass: '' },
                                    { tdText: (item.MaterialID || ' '), c: 0, r: 0, tdHtml: '', tdId: '', tdClass: '' },
                                    { tdText: (item.SizeName || ' '), c: 0, r: 0, tdHtml: '', tdId: '', tdClass: '' },
                                    { tdText: (item.SuppleQty || ' '), c: 0, r: 0, tdHtml: '', tdId: '', tdClass: '' },
                                    { tdText: (item.Qty || ' '), c: 0, r: 0, tdHtml: '', tdId: '', tdClass: '' },
                                    { tdText: (item.can_supply_qty || ' '), c: 0, r: 0, tdHtml: '', tdId: '', tdClass: '' },
                                    { tdText: (item.SuppleDate || ' '), c: 0, r: 0, tdHtml: '', tdId: '', tdClass: '' },
                                    { tdText: (item.Round || ' '), c: 0, r: 0, tdHtml: '', tdId: '', tdClass: '' }
                                ]
                            };
                            tBody.push(tempTr);
                        })
                    rScroll();
                    pageList = [];
                    pageList = result;
                }
                tableControl.initTbody('.footable', (tBody.length > 0 ? tBody : null), 8, null);
            });
        }
        loadList();
        
        //查询按钮
        $('.btns-container').on('click', '#btn-search', function () {
            page = 1;
            loadList();
        });
        //下载Excel
        $(".btns-container").on("click", '#downloadBtn', function () {
            /*
            *conditionJSON是一个数组
            *数组由多个对象组成，对象格式{ column: "ShopName", value: $('#keys').val(), operator: "like", connector: "and" }
            *column是列名，如果是连接查询，使用了别名，这里要写别名，例如a.Name:"xiaoMing"
            *value是列值，对应的列名的值
            *operator是操作符，如like,>,<,=，必填*
            *connector是连接符，如and，or，根据需求设置，必填*
            */
            var conditionJSON = [];
            conditionJSON.push({ column: "ShopName", value: $('#keys').val(), operator: "like", connector: "and" });
            //如果不是选中的所有尺码，就将尺码加入到筛选条件
            if ($('#search-size-name').val().length > 0) {
                conditionJSON.push({ column: "SizeName", value: $('#search-size-name').val(), operator: "=", connector:"and"});
            }
            conditionJSON = JSON.stringify(conditionJSON);            
            $.Export({
                filetype: 'supply',
                filename: '补货需求单',
                //进行编码，防止有特殊字符被过滤截断，如=
                conditions: encodeURIComponent(conditionJSON),
                after: function () {
                    //回调方法
                    //loadList(1);
                    swal("导出成功!");
                }
            });
        });

    });
</script>
</asp:Content>

